<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var arr=[{
            "firstname":"王",
            "lastname":["安石","维","3","4","5"]
        },{
            "firstname":"李",
            "lastname":["白","逵","3","4","5"]

        },{
            "firstname":"张",
            "lastname":["泽","飞","若须","4","5"]
        },{
            "firstname":"欧",
            "lastname":["修","峰","修士","4","5"]
        }];
        //prompt与alert类似，但prompt()可以拿到返回值
        var result=prompt("请输入你的今生姓名：");
        console.log(result);
        var res=result.charAt(0);
        for(var i=0;i<arr.length;i++){
            if(res==arr[i].firstname){
            var res2=arr[i].lastname[Math.floor(Math.random()*5)];
            console.log("您的前世姓名是："+res+res2);
            }
        }
        
        
    </script>
</head>
<body>
    
</body>
</html>